package com.alexwan.nightnote.ui.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.alexwan.nightnote.R;
import com.alexwan.nightnote.bean.NoteBean;

/**
 * 笔记列表适配
 * 
 * @author alexwan
 * 
 */
public class NoteListAdapter extends ArrayListAdatper<NoteBean> {
	private NoteBean mNoteBean;

	public NoteListAdapter(Activity mContext) {
		super(mContext);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder mViewHolder;
		View mView = convertView;
		if (mView == null) {
			mViewHolder = new ViewHolder();
			mView = LayoutInflater.from(mContext).inflate(
					R.layout.item_note_list, null);
			mViewHolder.mNoteDate = (TextView) mView
					.findViewById(R.id.note_date);
			mViewHolder.mNoteTitle = (TextView) mView
					.findViewById(R.id.note_title);
			mViewHolder.mNoteContent = (TextView) mView
					.findViewById(R.id.note_content);
			mView.setTag(mViewHolder);
		} else {
			mViewHolder = (ViewHolder) mView.getTag();
		}
		mNoteBean = mList.get(position);
		mViewHolder.mNoteDate.setText(mNoteBean.getmArticleDate());
		mViewHolder.mNoteTitle.setText(mNoteBean.getmArticleTitle());
		mViewHolder.mNoteContent.setText(mNoteBean.getmArticleContent());
		return mView;
	}

	private class ViewHolder {
		TextView mNoteDate;
		TextView mNoteTitle;
		TextView mNoteContent;
	}
}
